package nl.unimaas.micc.eventSnookerTest.simulation.event;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import nl.unimaas.micc.eventSnookerTest.adt.def.Position;
import nl.unimaas.micc.eventSnookerTest.adt.def.PositionContainer;
import nl.unimaas.micc.eventSnookerTest.adt.impl.KeyElementPair;
import nl.unimaas.micc.eventSnookerTest.domain.BilliardBall;

public abstract class Event
{		

	public Event(double time, Set<BilliardBall> balls)
	{
		this.time = time;
		this.balls = balls;
		this.listOccurrences = new ArrayList<Position<Event>>(2);
	}

	public void addListOccurrence(Position<Event> position)
	{
		listOccurrences.add(position);
	}
	
	public void setPQOccurrence(Position<KeyElementPair<Double, Event>> position)
	{
		pqOccurrence = position;
	}

	public void removeOccurrences()
	{
		for (Position<Event> p : listOccurrences)
		{
			p.container().remove(p);
		}
		pqOccurrence.container().remove(pqOccurrence);
	}

	public double getTime()
	{
		return time;
	}
	
	public Set<BilliardBall> getBalls()
	{
		return balls;
	}

	public String toString()
	{
		StringBuffer s = new StringBuffer("Event: " + this.getClass().getSimpleName() + "(t:"+getTime()+")");
		for(BilliardBall b : balls)
		{
			s.append(" :: " + b.getID());
		}
		return s.toString();
	}

	public abstract void handle();

	private double time;
	private Set<BilliardBall> balls;
	private ArrayList<Position<Event>> listOccurrences;
	private Position<KeyElementPair<Double, Event>> pqOccurrence;
}
